const message = require('../model/returnMessage');
const {
  getCommentListOfPost,
  getCommentById,
  addComment,
  likeComment,
  unlikeComment,
  deleteComment
} = require('../model/comment');

module.exports.getCommentListOfPost = async (req, res, next) => {
  getCommentListOfPost(req.params.id).then(
    (r) => {
      res.status(200).json(message(r, 'Get commentList.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.getCommentById = async (req, res, next) => {
  getCommentById(req.params.id).then(
    (r) => {
      res.status(200).json(message(r, 'Get comment.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.addComment = async (req, res, next) => {
  addComment(req.body).then(
    (r) => {
      res.status(201).json(message(req.body, 'Comment created.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.likeComment = async (req, res, next) => {
  likeComment(req.params.id).then(
    (r) => {
      res.status(201).json('Comment liked.');
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.unlikeComment = async (req, res, next) => {
  unlikeComment(req.params.id).then(
    (r) => {
      res.status(201).json('Comment unliked.');
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};

module.exports.deleteComment = async (req, res, next) => {
  deleteComment(req.params.id).then(
    (r) => {
      res.status(200).json(message(r, 'Comment deleted.'));
    },
    (e) => {
      res.status(500).json(message(e, 'Internal server error.'));
    }
  );
};
